package com.baosight.risk.web.xtzy;

import java.util.List;

import javax.ws.rs.core.MediaType;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.baosight.risk.api.xtzy.IXtzyRoleShiftService;
import com.baosight.risk.base.controller.BaseController;
import com.baosight.risk.common.annotation.Log;
import com.baosight.risk.common.enums.BusinessType;
import com.baosight.risk.common.result.AjaxResult;
import com.baosight.risk.service.xtzy.entity.XtzyRoleShift;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;

/**
 * 
 * @author zzw
 *
 */
@Slf4j
@RestController
@RequestMapping("/xtzy/roleshift")
@Api(value = "权限移交", description = "权限移交", produces = MediaType.APPLICATION_JSON)
public class XtzyRoleShiftController extends BaseController {
    @Autowired
    private IXtzyRoleShiftService roleShiftService;
    
    @Log(title = "权限移交查询")
    @RequestMapping(value = "list", method = RequestMethod.POST)
    public AjaxResult list(@RequestBody XtzyRoleShift shift) {
        log.info("权限移交查询参数：" + shift.toString());
        startPage();
        return getResultPage(roleShiftService.listByRoleCode(shift.getRoleCode()));
    }
    
    /**
     * 保存权限移交
     * @param shift
     * @return
     */
    @PostMapping("save")
    @Log(title = "保存权限移交")
    @ApiOperation("保存权限移交")
    @RequiresPermissions("xtzy:roleshift:save")
    public AjaxResult save(@RequestBody List<XtzyRoleShift> shifts) {
        log.info("保存权限移交：" + shifts.toString());
        for(XtzyRoleShift shift : shifts){
        	roleShiftService.save(shift);
        }
        return toAjax(1);
    }
    
    /**
     * 删除权限移交
     * @param id
     * @return
     */
    @PostMapping("delete")
    @Log(title = "删除权限移交", businessType = BusinessType.DELETE)
    @RequiresPermissions("xtzy:roleshift:delete")
    @ApiOperation("删除权限移交")
    public AjaxResult delete(@RequestBody List<String> ids) {
        return toAjax(roleShiftService.deleteByIds(ids));
    }

}
